def func(self, max_tracks, tracks, ret_tracks):

	least_played = self.getPlayedCount(tracks, True)

	most_played = self.getPlayedCount(tracks, False)

	results = set()

	while len(results) < max_tracks and len(results) < len(tracks):
		batch_max = max_tracks

		batch_tracks = list(self.filterPlayCount(tracks, least_played))

		if len(batch_tracks) == 0:
			least_played += 1

			if least_played > most_played:
				break
			continue

		if batch_max > len(batch_tracks):
			batch_max = len(batch_tracks)

                random.shuffle(batch_tracks)

		batch_add = set(self.load_tracks(batch_tracks, batch_max))

		results |= batch_add

		max_tracks -= len(batch_add)

		least_played += 1

		self.stats_played_count(batch_add)

	ret_tracks |= results
